import { _decorator, Component, instantiate, Label, Node, tween, Vec3 } from 'cc';
import { ResMgr } from '../Mgr/ResMgr';
import { AssetList } from '../Global';
const { ccclass, property } = _decorator;

@ccclass('AddScoreLoad')
/**
 * 加分层
 */
export class AddScoreLoad extends Component {

    //加分提示数组
    public AddScoreArr: Node[] = [];
    //没用得数组
    public NoUse: Node[] = [];

    /**
     * 创建加分提示
     */
    public AddAddScore(_score: number, _pos: Vec3) {
        if (this.NoUse.length > 0) {
            let as = this.NoUse[0];
            as.active = true;
            this.NoUse.splice(0, 1);
            as.getChildByName("Label").getComponent(Label).string = _score.toString();
            as.setWorldPosition(_pos);
            tween(as).to(0.5, { worldPosition: _pos.add(new Vec3(0, 20)) }).call(() => {
                as.active = false;
                this.NoUse.push(as);
            }).start();
        } else {
            let as: Node = instantiate(ResMgr.Instance.Prefabs[AssetList.Prefabs.AddScore]);
            as.getChildByName("Label").getComponent(Label).string = _score.toString();
            this.node.addChild(as);
            as.setWorldPosition(_pos);
            tween(as).to(0.5, { worldPosition: _pos.add(new Vec3(0, 20)) }).call(() => {
                as.active = false;
                this.NoUse.push(as);
            }).start();
        }

    }
}

